﻿using Modbus.Device;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace DeltaPlcSystem
{
    public class ModbusTcp
    {
        public IModbusMaster master;
        public Ping ping;
        public TcpClient tcpClient=null;

        public ModbusTcp()
        {
            ping = new Ping();
        }


        public  ushort[] ReadHoldingRegister(byte slave, ushort startAdd, ushort num)
        {
            //try
            //{

            return master.ReadHoldingRegisters(slave, startAdd, num);



        }


      
        public  bool[] ReadCoil(byte slave, ushort startAdd, ushort num)
        {
            //try
            //{

            return master.ReadCoils(slave, startAdd, num);


        }






        public  void WriteSingleRegister(byte slave, ushort startAdd, ushort num)
        {
            //try
            //{

            master.WriteSingleRegister(slave, startAdd, num);


        }


        public  void WriteSingleCoil(byte slave, ushort startAdd, bool num)
        {
            try
            {
                master.WriteSingleCoil(slave, startAdd, num);
            }
            catch
            { }




        }

    }
}
